package com.ruoyi.web.controller.part;

import java.util.List;

import com.ruoyi.system.service.IPartTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PartLot;
import com.ruoyi.system.service.IPartLotService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 停车场信息Controller
 *
 * @author ruoyi
 * @date 2023-11-30
 */
@Controller
@RequestMapping("/part/partLot")
public class PartLotController extends BaseController {
    private String prefix = "part/partlot";

    @Autowired
    private IPartLotService partLotService;

    @Autowired
    private IPartTypeService partTypeService;

    @RequiresPermissions("part:partLot:view")
    @GetMapping()
    public String partLot(ModelMap mmap) {
        mmap.put("partTypes", partTypeService.selectPartTypeList(null));
        return prefix + "/partLot";
    }

    /**
     * 查询停车场信息列表
     */
    @RequiresPermissions("part:partLot:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PartLot partLot) {
        startPage();
        List<PartLot> list = partLotService.selectPartLotList(partLot);
        return getDataTable(list);
    }

    /**
     * 导出停车场信息列表
     */
    @RequiresPermissions("part:partLot:export")
    @Log(title = "停车场信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PartLot partLot) {
        List<PartLot> list = partLotService.selectPartLotList(partLot);
        ExcelUtil<PartLot> util = new ExcelUtil<PartLot>(PartLot.class);
        return util.exportExcel(list, "停车场信息数据");
    }

    /**
     * 新增停车场信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("partTypes", partTypeService.selectPartTypeList(null));
        return prefix + "/add";
    }

    /**
     * 新增保存停车场信息
     */
    @RequiresPermissions("part:partLot:add")
    @Log(title = "停车场信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PartLot partLot) {
        return toAjax(partLotService.insertPartLot(partLot));
    }

    /**
     * 修改停车场信息
     */
    @RequiresPermissions("part:partLot:edit")
    @GetMapping("/edit/{partLotId}")
    public String edit(@PathVariable("partLotId") Long partLotId, ModelMap mmap) {
        PartLot partLot = partLotService.selectPartLotByPartLotId(partLotId);
        mmap.put("partTypes", partTypeService.selectPartTypeList(null));
        mmap.put("partLot", partLot);
        return prefix + "/edit";
    }

    /**
     * 修改保存停车场信息
     */
    @RequiresPermissions("part:partLot:edit")
    @Log(title = "停车场信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PartLot partLot) {
        return toAjax(partLotService.updatePartLot(partLot));
    }

    /**
     * 删除停车场信息
     */
    @RequiresPermissions("system:partLot:remove")
    @Log(title = "停车场信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(partLotService.deletePartLotByPartLotIds(ids));
    }
}
